import java.applet.Applet;
import java.applet.AudioClip;
import java.net.MalformedURLException;
import java.net.URL;

/**
 * 声音管理
 *
 * @author traveller
 * @create 2020-07-22 15:51
 * @since 1.0.0
 */
public class Sound {

    private GameFrame gameFrame;

    //经过我的仔细试听，QQ连连看的闪电音效是两个音效重叠一起放的，很带感
    public AudioClip sound_lightning;//闪电
    public AudioClip sound_lightning1;//闪电1
    public AudioClip sound_click;//选择方块
    public AudioClip sound_explode;//爆炸
    public AudioClip sound_start;//游戏开始
    public AudioClip sound_win;//游戏胜利
    public AudioClip sound_item;//使用道具

    //背景音乐
    public AudioClip sound_bg_default;//背景音乐默认

    public Sound(){

    }

    /**
     * 背景音乐比较大，加载会有延迟
     */
    public Sound(GameFrame gameFrame) throws MalformedURLException {
        this.gameFrame = gameFrame;
        //getClass().getResource()导出jar后路径会额外多一个感叹号!导致找不到目录，这里处理一下
        String cPath = gameFrame.getClass().getResource("sound").toString();
        //初始化所有音乐音效
        sound_click = Applet.newAudioClip(new URL(cPath + "/sel.wav"));
        sound_lightning = Applet.newAudioClip(new URL(cPath + "/elec.wav"));
        sound_lightning1 = Applet.newAudioClip(new URL(cPath + "/elec.wav"));
        sound_explode = Applet.newAudioClip(new URL(cPath + "/itemboom.wav"));
        sound_start = Applet.newAudioClip(new URL(cPath + "/start.wav"));
        sound_win = Applet.newAudioClip(new URL(cPath + "/zhangsheng.wav"));
        sound_item = Applet.newAudioClip(new URL(cPath + "/flystar.wav"));

        //初始化背景音乐
        gameFrame.update(gameFrame.getGraphics());//刷新 资源加载中 进度
        sound_bg_default = Applet.newAudioClip(gameFrame.getClass().getResource("sound/bg.mid"));
    }

}
